package com.gxa.controller;

import com.gxa.pojo.Cvm;
import com.gxa.pojo.Goods;
import com.gxa.utils.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.text.ParseException;
import java.text.SimpleDateFormat;

/**
 * Created with IntelliJ IDEA.
 * User: hw
 * Date: 2020/11/26 21:35
 * Description:
 * Version: V1.0
 */
@RestController
@RequestMapping("/cvm")
@Api(value = "卡券管理",tags = "卡券管理API")
public class CvmController {

    @Autowired(required = false)
    private ResponseData responseData;

    @RequestMapping(value = "/queryCvmById",produces = "application/json;charset=utf-8")
    @ApiOperation(value = "根据ID查询卡券信息",notes = "根据ID查询卡券信息",httpMethod = "GET")
    public ResponseData queryCvmById(Integer cvmId){

        if (cvmId > 0){
            Cvm cvm = new Cvm();
            Goods goods = new Goods();
            cvm.setCvmId(1);
            cvm.setCvmRn("卡卷1");
            cvm.setCvmNo("CS0001");
            cvm.setCvmBatch(28287915);
            try {
                cvm.setCvmStart(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2020-12-01 09:30:17"));
            } catch (ParseException e) {
                e.printStackTrace();
            }
            goods.setGoodsName("大闸蟹礼品套装");
            cvm.setGoods(goods);
            cvm.setCvmStatus(1);
            cvm.setCvmUs(1);
            try {
                cvm.setCvmEd(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2020-11-01 06:06:06"));
            } catch (ParseException e) {
                e.printStackTrace();
            }
            try {
                cvm.setCvmEdf(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").parse("2020-11-11 08:08:08"));
            } catch (ParseException e) {
                e.printStackTrace();
            }
            if (cvm != null){
                responseData.setCode(200);
                responseData.setMsg("查询成功");
                responseData.setData(cvm);
            }else {
                responseData.setCode(500);
                responseData.setMsg("查询失败");
            }
            return responseData;
        }else{
            responseData.setCode(500);
            responseData.setMsg("查询失败");
        }
        return responseData;
    }

    @RequestMapping(value = "/updateCvmById",produces = "application/json;charset=utf-8")
    @ApiOperation(value = "根据ID修改卡券信息",notes = "根据ID修改卡券信息",httpMethod = "POST")
    public ResponseData updateCvmById(Integer cvmId){

        if (cvmId > 0){
            responseData.setCode(200);
            responseData.setMsg("修改成功");
        }else {
            responseData.setCode(500);
            responseData.setMsg("修改失败");
        }
        return responseData;
    }

    @RequestMapping(value = "/delCvmById",produces = "application/json;charset=utf-8")
    @ApiOperation(value = "根据ID删除卡券信息",notes = "根据ID删除卡券信息",httpMethod = "POST")
    public ResponseData delCvmById(Integer cvmId){

        if (cvmId > 0){
            responseData.setCode(200);
            responseData.setMsg("修改成功");
        }else {
            responseData.setCode(500);
            responseData.setMsg("修改失败");
        }
        return responseData;
    }

    @RequestMapping(value = "/updateCvmStatuById",produces = "application/json;charset=utf-8")
    @ApiOperation(value = "根据ID修改卡券激活状态",notes = "根据ID修改卡券激活状态",httpMethod = "POST")
    public ResponseData updateCvmStatuById(Integer[] cvmId){

        for (Integer integer : cvmId) {

            if (integer > 0){
                responseData.setCode(200);
                responseData.setMsg("激活成功");
            }else {
                responseData.setCode(500);
                responseData.setMsg("激活失败");
            }
        }
        return responseData;
    }

    @RequestMapping(value = "/addCvm",produces = "application/json;charset=utf-8")
    @ApiOperation(value = "添加卡券信息",notes = "添加卡券信息",httpMethod = "POST")
    public ResponseData addCvm(Cvm cvm){

        if (cvm != null){
            responseData.setCode(200);
            responseData.setMsg("添加成功");
        }else {
            responseData.setCode(500);
            responseData.setMsg("添加失败");
        }
        return responseData;

    }
}
